<?php
require_once('../config/auth.php');
require_once('employe.cl.php');
$__CURRENT_PAGE__ = 'employe';
$__TITLE__ = "Formulaire d'ajouter un employé";
$employe = new Employe();
$services = $employe->getService()->getServiceByDepartementId($employe->getService()->getDepartementId());
$departements = $employe->getService()->getDepartement()->getAllDepartements();

$message = '';
$title="Ajouter un employé";
if(count($_POST) > 0 ) {
  //debug($_POST);
  $employeData = $employe->save($_POST);
    if(!$employe->hasError()) {
        $message = "<div class='alert alert-success' class='span4'>Employé sauvegardés avec succès</div>";
    }
}
elseif(!empty($_GET['id'])) {
    $employe->loadEmployeById($_GET['id']);
    $title="Modifier l'employé";
}
require_once(dirname(__FILE__).'/../config/head.php'); 
?>
<body> 
<?php require_once(dirname(__FILE__).'/../config/menu.php'); ?>
<div class="container employeForm">
 <h1><?php echo($title)?></h1>
 <?php echo $message ?>
 <form method="post" class="form">
  <input type="hidden" name="id" value="<?php echo $employe->getId() ?>" />
<div class="row">
    <div class="span4">
      <label>Département:</label>
      <select name="departement_id" id="departement_id">
              <option value="">--Selectionner un departement--</option>
              <?php foreach($departements as $depart): ?>
                <option <?php echo ($employe->getService()->getDepartementId() == $depart->id)  ? 'selected="selected"' : '' ?>
                value="<?php echo $depart->id?>"><?php echo $depart->name ?></option>   
              <?php endforeach ?>
      </select>
    </div>
    <div class="span4"> 
      <label>Service:</label>
      <select name="service_id" id="service_id">
              <option value="">--Selectionner un service--</option>
              <?php foreach($services as $serv): ?>
                <option <?php echo ($employe->getServiceId() == $serv->id)  ? 'selected="selected"' : '' ?>
                value="<?php echo $serv->id?>"><?php echo $serv->name ?></option> 
              <?php endforeach ?>
      </select>
      <?php echo $employe->getError('service_id') ?>
    </div>
</div>

<div class="row">
  <div class="span4">      
       <label>Matricule:</label>
       <input type="text" name="matricule" class="input-small"  value="<?php echo $employe->getMatricule() ?>">
       <?php echo $employe->getError('matricule') ?>
  </div> 
    <div class="span4">
        <label>Poste:</label>
        <select name="type">
          <option value="">--Selectionner un type--</option>
          <option <?php echo ($employe->getType()=="Ingenieur")  ? 'selected="selected"' : '' ?> value="Ingenieur">Ingenieur</option>
          <option <?php echo ($employe->getType()=="Agent")  ? 'selected="selected"' : '' ?> value="Agent">Agent</option>
        </select>
        <?php echo $employe->getError('type') ?>
    </div>
    <!--<div class="span2">
       <label>Ordre de garde:</label>
       <input type="text" class="input-small" name="order"  value="<?php //echo $employe->getOrder() ?>">
       <?php //echo $employe->getError('order') ?>
    </div>-->
</div>

<div class="row">
   <div class="span4">
       <label>Nom:</label>
       <input type="text" name="last_name"  value="<?php echo $employe->getLastName() ?>">
       <?php echo $employe->getError('last_name') ?>
   </div>

   <div class="span4">
       <label>Prénom:</label>
       <input type="text" name="first_name"  value="<?php echo $employe->getFirstName() ?>">
       <?php echo $employe->getError('first_name') ?>
   </div>
</div>

<div class="row">
   <div class="span4">
       <label>Telephone de bureau:</label>
       <input type="text" name="tele_bureau"  value="<?php echo $employe->getTele_bureau() ?>">
       <!--<?php //echo $employe->getError('tele_bureau') ?>-->
   </div>
   <div class="span4">
       <label>GSM:</label>
       <input type="text" name="gsm"  value="<?php echo $employe->getGSM() ?>">
       <?php echo $employe->getError('gsm') ?>
   </div>
</div>

<div class="row">
   <div class="span8">
       <label>Adresse:</label>
       <input type="text" class="input-xxlarge" name="adresse"  value="<?php echo $employe->getAdresse() ?>">
       <?php echo $employe->getError('adresse') ?> 
   </div>
</div>

<?php if(!empty(getSession()->id) && (getSession()->id == $employe->getId()) ): ?>
<div class="row">
   <div class="span4">
       <label>Password:</label>
       <input type="password" name="password"  value="<?php echo $employe->getPassword() ?>">
       <?php echo $employe->getError('password') ?>
   </div>
</div>
<?php endif ?>

<div class="row">
<div class="span2">
   <input type="reset" value="Annuler" class="btn btn-large btn-block">
 </div>
 <div class="span2 offset3">
   <input type="submit" value="Valider" class="btn btn-success btn-large btn-block">
 </div>
</div>

  </form>
 </div>
</body>
